

use "$clean/clean_all.dta" ,clear



gen underestimator = prior_comp<56
gen overestimator = prior_comp>=56


gen update = posterior_comp - prior_comp

egen bin_prior = xtile(prior_comp) if prior_comp<=56 ,n(4)
egen bin_prior2 = xtile(prior_comp) if prior_comp>56 ,n(2)
replace bin_prior =bin_prior2 +4  if prior_comp>56



gen coeff_t = . in 1/6
gen ci_tu = . in 1/6
gen ci_tl = . in 1/6

gen coeff_ct = . in 1/6
gen ci_cu = . in 1/6
gen ci_cl = . in 1/6

gen bin =_n in 1/6

bys bin_prior: sum  prior_comp

*midpoints*
replace bin = 2.5 in 1
replace bin = 8 in 2
replace bin = 15.5 in 3
replace bin = 38 in 4
replace bin = 66.5 in 5
replace bin = 88 in 6


forval l=1/6 {

reg  update  if  bin_prior==`l' & treatment==1,  r
replace coeff_t=_b[_cons] in `l'
replace ci_tu =_b[_cons] +1.96* _se[_cons] in `l'
replace ci_tl =_b[_cons] -1.96*_se[_cons] in `l'

reg  update  if  bin_prior==`l' & treatment==0,  r
replace coeff_c=_b[_cons] in `l'
replace ci_cu =_b[_cons] +1.96*_se[_cons] in `l'
replace ci_cl =_b[_cons] -1.96*_se[_cons] in `l'

}

kdensity prior_comp, lp(dash)   addplot((scatter coeff_t bin,  msize(small)) (rcap ci_tu ci_tl  bin) ///
	   (scatter coeff_c bin,  msize(small) ) (rcap ci_cu ci_cl  bin) ) ///
	   ytitle("{&Delta} post- and pre-treatment beliefs", axis(1))  note("") ///
	   legend(pos(6) order(2 "Treatment" 4 "Control " 3 "95% CI" 1 "Kernel density estimate" ) rows(2)) ///
	   xline(56) title("") xtitle("pre-treatment beliefs") yaxis(2)   ytitle("Kernel density estimate", axis(2)) 
		
 graph export "$figures/Figure_A4.pdf", replace as(pdf)
 
 
 
